const query = require("../config/db")
var express = require("express")
var router  = express.Router()

router.get("/course",async(req,res,next)=>{
    let {cid} = req.query
    let sql = `select * from e_course where cid='${cid}'`
    let result = await query(sql)

    if(result.length === 0){
        next("该数据不存在")
        return
    }

    let course = result[0]

    let sql2 = `select * from e_teacher where tid='${course.tid}'`
    let result2 = await query(sql2)
    let teacher = result2[0]

    let sql3 = `select * from e_video where cid='${course.cid}' order by vnum`

    let video = await query(sql3)

    res.send({
        success:true,
        msg:"查询成功",
        status:200,
        data:{
            course,
            teacher,
            video
        }
    })
})

module.exports = router